<?php
require_once "admin/Model/Home.php";
$modelHome = new Home;
$mod = isset($_GET['mod']) ? $_GET['mod'] : "";

function checkCat($uri) {
    $pattern_detail = '#[a-zA-Z0-9\-]+\-\d+.html#';
 
	$pattern_contact = '#/lien-he+.html#';      
    $pattern_menu = '#[a-z0-9\-]+.html#';


    $mod = "";
    if (preg_match($pattern_menu, $uri)) {
        $mod = "menu";
    }
   
    if (preg_match($pattern_contact, $uri)) {
        $mod = "contact";
    }    

    if (preg_match($pattern_detail, $uri)) {
        $mod = "detail";
    }

    return $mod;
}

$uri = str_replace("/mercy", "", $_SERVER['REQUEST_URI']);
$mod = checkCat($uri);
$uri = str_replace(".html", "", $uri);
$tmp_uri = explode("/", $uri);
//var_dump($tmp_uri);
switch ($mod) {
    case "menu":        
            $cate_alias = end($tmp_uri);
            $rs_cate = $modelHome->getDetailCateByAlias($cate_alias);
            $row_detail_cate = mysql_fetch_assoc($rs_cate);
            $list_type = $row_detail_cate['type'];
            $cate_id = $row_detail_cate['cate_id'];
            if($row_detail_cate['parent_id']==0){                
                $rs_product = ($list_type==1) ? $modelHome->getListProductByCategoryNew('full_parent',$cate_id) :  $modelHome->getListArticleByCategoryNew('full_parent',$cate_id) ; 
            }else{                
                $rs_product = ($list_type==1) ? $modelHome->getListProductByCategoryNew('category_id',$cate_id) : $modelHome->getListArticleByCategory('category_id',$cate_id);
                $rs_cate_parent = $modelHome->getDetailCateByID($row_detail_cate['parent_id']);
                $row_detail_cate_parent = mysql_fetch_assoc($rs_cate_parent);
            }           
            
            $title = $row_detail_cate["seo_title"];
            $metaD = $row_detail_cate["seo_description"];
            $metaK = $row_detail_cate["seo_keyword"];
   
        break;
    case "detail":
        $tieude_id = end($tmp_uri);
        $arr = explode("-", $tieude_id);
        $article_id = (int) end($arr);
        $rs_article = $modelHome->getDetailArticle($article_id);
        $arrDetailArticle = mysql_fetch_assoc($rs_article);
        $rs_cate_parent = $modelHome->getDetailCateByID($arrDetailArticle['category_id']);
        $row_detail_cate_parent = mysql_fetch_assoc($rs_cate_parent);
        $title = $arrDetailArticle["seo_title"];
        $metaD = $arrDetailArticle["seo_description"];
        $metaK = $arrDetailArticle["seo_keyword"];
        break;

    default :
            $title = "MERCY.VN - Wedding Services";
            $metaD = "MERCY.VN - Wedding Services";
            $metaK = "MERCY.VN - Wedding Services";

        break;
}
?>